package com.wx.task.future.v1;

import java.util.concurrent.*;

/**
 * 泡茶
 *用两个线程 T1 和 T2 来完成烧水泡茶程序，
 * T1 负责洗水壶、烧开水、泡茶这三道工序，
 * T2 负责洗茶壶、洗茶杯、拿茶叶三道工序，
 * 其中 T1 在执行泡茶这道工序时需要等待 T2 完成拿茶叶的工序
 *
 * @author wang.xun
 * @date 2023/08/03
 */
public class PaoCha {
    public static void main(String[] args) {

        t2Task t2Task = new t2Task();
        FutureTask<String> task2 = new FutureTask<>(t2Task);
        t1Task t1Task = new t1Task(task2);

        FutureTask<Boolean> task1 = new FutureTask<>(t1Task);

        ExecutorService executor = Executors.newFixedThreadPool(2);

        Future<?> future = executor.submit(task1);

        executor.submit(task2);

        try {
            future.get();
            executor.shutdown();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }


    }
}
